package com.lanxiao.cloud.modules.oauth.controller;

import com.lanxiao.cloud.common.core.constant.LanXiaoConstant;
import com.lanxiao.cloud.common.core.enums.OperationType;
import com.lanxiao.cloud.common.core.service.IOperatorService;
import com.lanxiao.cloud.common.redis.template.RedisTemplateUtils;
import com.lanxiao.cloud.common.web.invalid.Log;
import com.lanxiao.cloud.modules.oauth.infrastructure.constant.OauthRedisConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：qiaoliang
 * @date ：2021-09-14
 */
@Api(tags = "登录")
@Validated
@RequestMapping("/oauths")
@RestController
public class LogOutController {

  private final IOperatorService operatorService;

  public LogOutController(IOperatorService operatorService) {
    this.operatorService = operatorService;
  }

  @ApiOperation(value = "退出登录")
  @DeleteMapping("/logout")
  public ResponseEntity<?> logout() {
    final Long operator = operatorService.operator();
    RedisTemplateUtils.delectHash(OauthRedisConstant.OAUTH_TOKEN, operator.toString());
    RedisTemplateUtils.delectHash(OauthRedisConstant.OAUTH_PERMISSION, operator.toString());
    return ResponseEntity.status(HttpStatus.CREATED).build();
  }

}
